<?php
class DigCms_View_Helper_DigCmsItemTree extends Zend_View_Helper_HtmlElement
{
    public function digCmsItemTree($tree, $itemTemplate, $options = array(), $levels = null, $showTypes = null, $currentLevel = 1)
    {
        if($levels != null && $currentLevel > $levels) {
            return false;
        }
        if(!is_array($tree)) {
            $tree = array($tree);
        }
        if(count($tree) > 0) {
            $treeItems = array();
            foreach ($tree as $item) {
                if( $item instanceof DigCms_Model_Item ) {
                    if( $showTypes == null || in_array($item->namespace, $showTypes) ) {
                        $treeItems[] = $this->view->digItemTemplate($item, $itemTemplate) .
                            $this->view->digCmsItemTree($item->children(), $itemTemplate, $options, $levels, $showTypes, $currentLevel++);
                    }
                }
            }
            if(count($treeItems) > 0) {
                if($currentLevel == 1) {
                    if(isset($options['class'])) {
                        $options['class'] .= ' tree';
                    } else {
                        $options['class'] = 'tree';
                    }
                }
                return $this->view->htmlList($treeItems, null, $options, false);
            }
        }
        
    }
}
?>

        